package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import com.project.domain.bo.MiddleCheckOrCompleteBo;
import com.project.domain.entity.BizProjectMiddleCheck;
import com.project.domain.vo.BizProjectMiddleCheckVo;
import com.project.service.IBizProjectMiddleCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 项目中检
 */

@Api(tags = "项目中检")
@RestController
@RequestMapping("/pro/middleCheck")
public class MiddleCheckController extends BaseController {
    @Autowired
    private IBizProjectMiddleCheckService bizProjectMiddleCheckService;

    @ApiOperation("列表左上方统计")
    @GetMapping("/groups")
    public AjaxResult groups(MiddleCheckOrCompleteBo bizProjectMiddleCheck){
        return success(bizProjectMiddleCheckService.selectGroups(bizProjectMiddleCheck));
    }

    /**
     * 查询项目中检列表
     */
    @ApiOperation("查询项目中检列表")
    @GetMapping("/list")
    public TableDataInfo list(MiddleCheckOrCompleteBo bizProjectMiddleCheck)
    {
        IPage<BizProjectMiddleCheckVo> list = bizProjectMiddleCheckService.selectBizProjectMiddleCheckList(bizProjectMiddleCheck,"select");
        return TableDataInfo.build(list.getRecords(),list.getTotal());
    }

    /**
     * 导出项目中检列表
     */
    @ApiOperation("导出项目中检列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody MiddleCheckOrCompleteBo bizProjectMiddleCheck)
    {
        IPage<BizProjectMiddleCheckVo> list = bizProjectMiddleCheckService.selectBizProjectMiddleCheckList(bizProjectMiddleCheck,"export");
        ExcelUtil<BizProjectMiddleCheckVo> util = new ExcelUtil<BizProjectMiddleCheckVo>(BizProjectMiddleCheckVo.class);
        util.showColumn(bizProjectMiddleCheck.getExportStr().split(","));
        util.exportExcelByOrder(response, list.getRecords(), "项目中检数据",bizProjectMiddleCheck.getExportStr().split(","));
    }

    /**
     * 获取项目中检详细信息
     */
    @ApiOperation("获取项目中检详细信息")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(bizProjectMiddleCheckService.selectBizProjectMiddleCheckByID(ID));
    }

    /**
     * 新增项目中检
     */
    @ApiOperation("新增项目中检")
    @Log(title = "项目中检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProjectMiddleCheck bizProjectMiddleCheck)
    {
        return bizProjectMiddleCheckService.saveBizProjectMiddleCheck(bizProjectMiddleCheck,"add");
    }

    /**
     * 修改项目中检
     */
    @ApiOperation("修改项目中检")
    @Log(title = "项目中检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProjectMiddleCheck bizProjectMiddleCheck)
    {
        return bizProjectMiddleCheckService.saveBizProjectMiddleCheck(bizProjectMiddleCheck,"edit");
    }

    /**
     * 删除项目中检
     */
    @ApiOperation("删除项目中检")
    @Log(title = "项目中检", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(bizProjectMiddleCheckService.deleteBizProjectMiddleCheckByIDs(IDs));
    }
}
